import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem('token'),
    userInfo: JSON.parse(sessionStorage.getItem('userInfo')),
    needLogin: false, //需要登录标志
    msg:'',   //修改密码后重登陆时用于显示的消息
    timestamp: 1,  //时间戳，用于更换头像后，改变时间戳并加在ajax请求后面改变url防止浏览器缓存原因不更新头像
    activeIndex: '/index' ,    //头部导航菜单被选中的项的索引
    isPC: true,    //是PC端还是移动端
    router_loading: true   //正在路由时Home页面显示加载图标
  },
  getters: {   //getter
  },
  mutations: {  //setter
    set_token: (state, token) => {
      state.token = token;
      localStorage.setItem('token',token);
    },
    set_userInfo: (state, userInfo) => {
      state.userInfo = userInfo;
      sessionStorage.setItem('userInfo',JSON.stringify(userInfo));
    },
    reset_data: state => {
      localStorage.removeItem('token')
      sessionStorage.removeItem('userInfo')
      state.userInfo = '';
      state.token = '';
    },
    set_needLogin: (state, obj) =>{
      state.msg = obj.msg;
      state.needLogin = obj.flag;
    }
  },
  actions: {
  },
  modules: {
  }
})
